package com.xbongbong.util;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.saas.enums.business.PaymentEnum;

import java.util.Arrays;
import java.util.List;

/**
 * @author 吴峰
 * @date 2021/08/04 14:13
 */
public class PaymentUtil {

    /**
     * 覆盖导入时移除不能编辑的字段
     *
     * @param paymentJson 前端传过来的json格式
     * @param dbPaymentJson 存到数据库中的json格式
     */
    public static void removeUnCoverImportValue(JSONObject paymentJson, JSONObject dbPaymentJson) {
        List<String> shouldRemoveFieldList = Arrays.asList(PaymentEnum.PAYMENT_NO.getAttr(), PaymentEnum.AMOUNT.getAttr(),
                PaymentEnum.RECEIVABLE_PERIOD.getAttr(), PaymentEnum.ESTIMATE_TIME.getAttr(), PaymentEnum.SOURCE.getAttr(),
                PaymentEnum.SOURCE_LINK_TEXT.getAttr(), PaymentEnum.CUSTOMER.getAttr(), PaymentEnum.CONTRACT.getAttr(), PaymentEnum.STATUS.getAttr(),
                PaymentEnum.RECEIVABLES_ORIGIN_ID.getAttr(), PaymentEnum.RECEIVABLES_ORIGIN_LINK_TEXT.getAttr(), PaymentEnum.GENERATION_DATE.getAttr());
        for (String key : dbPaymentJson.keySet()) {
            if (!paymentJson.containsKey(key) || shouldRemoveFieldList.contains(key)) {
                paymentJson.put(key, dbPaymentJson.get(key));
            }
        }
    }
}
